/*
 * @Author: Seon.Hu SeonHu@126.com
 * @Date: 2023-03-15 13:29:28
 * @LastEditors: Seon.Hu SeonHu@126.com
 * @LastEditTime: 2023-03-15 13:30:35
 * @FilePath: \bg-vben\src\components\AdList\src\hooks\useLoading.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref, ComputedRef, unref, computed, watch } from 'vue';
import type { AdListProps } from '../types/adList';

export function useLoading(props: ComputedRef<AdListProps>) {
  const loadingRef = ref(unref(props).loading);

  watch(
    () => unref(props).loading,
    (loading) => {
      loadingRef.value = loading;
    },
  );

  const getLoading = computed(() => unref(loadingRef));

  function setLoading(loading: boolean) {
    loadingRef.value = loading;
  }

  return { getLoading, setLoading };
}
